package demo2;

import java.util.Arrays;

public class LeetCode611 {
    public int triangleNumber(int[] nums) {
        int n = nums.length, tmp = 0;
        Arrays.sort(nums);
        for (int i = 2; i < n; i++) {
            int left = 0, right = i - 1;
            while(left < right) {
                if(nums[left] + nums[right] > nums[i]) tmp += (right--) - left;
                else left++;
            }
        }
        return tmp;
    }
}
